package org.dey.controller;


import org.dey.entity.Result;
import org.dey.pojo.PageVo;
import org.dey.pojo.User;
import org.dey.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author deyran
 * @classname
 * @see UserController
 */
@RestController
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("user.do")
    public void Users() {
        List<User> users = userService.USER_LIST();
        users.forEach(System.out::println);
    }


    @RequestMapping("user2.do")
    public void test(){
        System.out.println("hello");
    }

    //    打开用户管理页面显示数据
    @PostMapping(value = "user.action/{pagecurrent}/{pagesize}")
    public PageVo<User> uerslist(@RequestBody User user, @PathVariable int pagecurrent, @PathVariable int pagesize){

        PageVo<User> alluers = userService.queryuser(user, pagecurrent, pagesize);

        return alluers;
    }

    //添加
    @PostMapping("user.action")
    public Result adduser(@RequestBody User user){

        Result insertuser = userService.insertuser(user);

        return insertuser;
    }

    //删除
    @DeleteMapping("user.action/{id}")
    public Result deluserbyid(@PathVariable int id){

        Result deluser = userService.deluser(id);

        return deluser;
    }

    //修改先根据id查到该数据
    @GetMapping("user.action/{id}")
    public User queryuserbyid(@PathVariable Integer id){

        User queryuserbyid = userService.queryuserbyid(id);

        return queryuserbyid;
    }

    //根据id修改
    @PutMapping("user.action")
    public Result updateuserbyid(@RequestBody User user){

        Result updateuserbyid = userService.updateuserbyid(user);

        return updateuserbyid;
    }

    @PostMapping ("login.do")
    public int User(@RequestBody User user){
        return userService.LOGIN(user);
    }

    @GetMapping("addroleqq.action/{userid}/{roleid}")
    public Result addroleqq(@PathVariable int userid,@PathVariable int roleid){
        return userService.addroleqq(userid,roleid);
    }
}
